<?php

namespace app\modules\setting\configs\office;

use app\common\enum\FormEnum;
use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\Json;
use app\modules\setting\models\office\EtcOfficeAddress;
use sookie\bootstraps\handlers\AuthChecker;

/**
* Class TestConfig
* @package sookie\react\configs
* app\modules\setting\configs\office\AddressConfig 模型的配置类
*/
class AddressConfig{

    /**
    * @return array
    * 获取搜索表单配置
    */
    public static function getSearchConfig(){
    return [
//            [
//                "component" => "FormSelect",
//                "field" => "user_id",
//                "label" => "所属",
//                "placeholder" => "所属",
//                "allowClear" => true,
//                "showSearch" => true,
//                "options" => EtcOfficeAddress::find()->select("user_id value,user_id name")->groupBy("user_id")->indexBy("name")->column(),
//            ],

    ];
    }

    /**
    * @return array
    * 获取表格的操作
    */
    public static function getTableActions(){
        return  [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "width" => 800,
                    "maskClosable" => true,
                    "title" => "新建",
                    "okText" => "提交",
                    "cancelText" => "取消",
                    "alert" => [
                        "type" => "info",
                        "message" => "小提示",
                        "width" => 600,
                        "description" => "请填写以下表单来新建数据"
                    ]
                ],
                "configUri" => UrlHandler::toAction("office/address","create"),
                "auth" => AuthChecker::doPermissionCheck("office/address","create"),
                "configParams" => new \ArrayObject(),
                "label" => "新建",
                "icon" => "plus",
                "type" => "primary",
            ],
        ];
    }

    /**
    * @return array
    * 获取表格行的操作
    * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
    * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
    */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => false,
                    "title" => "查看",
                    "alert" => [
                        "description" => "以下展示了该模型所有的字段信息"
                    ]
                ],
                "configUri" => UrlHandler::toAction("office/address","view"),
                "auth" => AuthChecker::doPermissionCheck("office/address","view"),
                "configParamsField" => ["id"],
                "label" => "查看"
            ],
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "title" => "编辑",
                    "alert" => [
                        "description" => "填写以下表单修改数据模型"
                    ]
                ],
                "configUri" => UrlHandler::toAction("office/address","update"),
                "auth" => AuthChecker::doPermissionCheck("office/address","update"),
                "configParamsField" => ["id"],
                "label" => "编辑"
            ],
            [
                "actionType" => "CONFIRM",
                "method" => "post",
                "configUri" => UrlHandler::toAction("office/address","delete"),
                "auth" => AuthChecker::doPermissionCheck("office/address","delete"),
                "configParamsField" => ["id"],
                "label" => "删除"
            ],
        ];
    }

    /**
    * @return array
    * 获取表格配置
    */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [

                [
                    "title" => "手机",
                    "dataIndex" => "phone",
                    "sorter" => true,
                    "key" => "phone",
                    "format" => "text",
                ],
                [
                    "title" => "收件人",
                    "dataIndex" => "name",
                    "sorter" => true,
                    "key" => "name",
                    "format" => "text",
                ],
                [
                    "title" => "详细地址",
                    "dataIndex" => "address",
                    "sorter" => true,
                    "key" => "address",
                    "format" => "text",
                ],
                [
                    "title" => "创建时间",
                    "dataIndex" => "create_at",
                    "sorter" => true,
                    "key" => "create_at",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
    * 首页配置
    */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }

    /**
    * @return array
    * 查看配置 format 可选 text pic video link
    */
    public static function configView(){
        return [
            "type" => "DETAIL",
            "config" => [

                [
                    "field" => "phone",
                    "label" => "手机",
                    "format" => "text",
                ],
                [
                    "field" => "name",
                    "label" => "收件人",
                    "format" => "text",
                ],
                [
                    "field" => "address",
                    "label" => "详细地址",
                    "format" => "text",
                ],
                [
                    "field" => "create_at",
                    "label" => "创建时间",
                    "format" => "text",
                ],
            ]
        ];
    }


    /**
    * @return array
    * 创建-表单配置
    */
    public static function configCreate(){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toPage("office/address")."/create",
            "config" => [
                [
                    "component" => "FormInput",
                    "field" => "phone",
                    "label" => "手机",
                    "placeholder" => "手机",
                    "allowClear" => true,
                    "initialValue" => "",
                    "rules" => [
                        [
                            'required' => true
                        ]
                    ],
                ],
                [
                    "component" => "FormInput",
                    "field" => "name",
                    "label" => "收件人",
                    "placeholder" => "收件人",
                    "allowClear" => true,
                    "initialValue" => "",
                    "rules" => [
                        [
                            'required' => true
                        ]
                    ],
                ],
                [
                    "component" => FormEnum::FormMulInput,
                    "field" => "address",
                    "label" => "详细地址",
                    "placeholder" => "详细地址",
                    "allowClear" => true,
                    "initialValue" => "",
                    "rules" => [
                        [
                            'required' => true
                        ]
                    ],
                ],
            ],
        ];
    }

    /**
    * @param ActiveRecord $model
    * @return array
    * 修改-表单配置
    */
    public static function configUpdate(ActiveRecord $model){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toAction("office/address","update",["id" => $model->id]),
            "config" => [
                [
                    "component" => "FormInput",
                    "field" => "phone",
                    "label" => "手机",
                    "placeholder" => "手机",
                    "allowClear" => true,
                    "initialValue" => $model->phone,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "name",
                    "label" => "收件人",
                    "placeholder" => "收件人",
                    "allowClear" => true,
                    "initialValue" => $model->name,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "address",
                    "label" => "详细地址",
                    "placeholder" => "详细地址",
                    "allowClear" => true,
                    "initialValue" => $model->address,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "create_at",
                    "label" => "创建时间",
                    "placeholder" => "创建时间",
                    "allowClear" => true,
                    "initialValue" => $model->create_at,
                    "rules" => [],
                ],
            ],
        ];
    }


}

